package org.smvcd1.controller1;

import org.apache.ibatis.annotations.Param;
import org.smvcd1.pojo.Person;
import org.smvcd1.pojo.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
@RequestMapping("/test5")
public class Test5Controller {
    @RequestMapping("/index1")
    public ModelAndView index1(HttpServletRequest request, HttpServletResponse response){
        System.out.println(request.getParameter("id"));
//        try {
//            response.setContentType("textml;charset=UTF-8");
//            request.setCharacterEncoding("UTF-8");
//            response.setCharacterEncoding("UTF-8");
//            response.getWriter().print("啦啦啦");
//            response.getWriter().close();
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

        request.setAttribute("msg","后添加的数据：");
        ModelAndView modelAndView=new ModelAndView("/test5_index1");
        modelAndView.addObject("msg3","456");

        return modelAndView;
    }



    @RequestMapping("/index2")
    public  String  index2(Model model, Integer id, String userName){
        model.addAttribute("msg2","123");
        System.out.println("id="+id+"userName="+userName);
        return "/test5_index2" ;
    }




    @RequestMapping("/index3")
    public  String  index3(HttpServletRequest request,Integer id,String userName){

        System.out.println("id="+request.getParameter("id")+"userName="+userName);
        return "/test5_index2" ;
    }





//    @RequestMapping("/index4")
//    public  String  index3(HttpSession session, Integer id, String userName){
//        session.getAttribute("张飞");
//        System.out.println("");
//        return "/test5_index2" ;
//    }
    @RequestMapping("/login")
public String login(){
        return  "/test5_login";
}

    @RequestMapping("/dologin")
public  String doLogin(Model model, UserInfo userInfo, Person person){

        System.out.println(person.getName());

    if(userInfo.getuName().equals("admin")){
      if(userInfo.getPwd().equals("123")){
          model.addAttribute("msg","登陆成功");
      } else {
          model.addAttribute("msg","登陆失败密码错误");
      }

    }else{
        model.addAttribute("msg","登陆失败，用户名错误");
    }


  return  "/test5_dologin"  ;
}





}
